﻿
window.copyText = function (id, text) {
    let node = document.getElementById(id);
    switch (node.nodeName) {
        case "TEXTAREA":
            node.select();
            break;
        default:
            let range = document.createRange()
            range.selectNodeContents(node)
            let selection = document.getSelection()
            selection.removeAllRanges()
            selection.addRange(range)
            break;
    }

    document.execCommand('Copy')
    // alert("复制成功!");
};

//$.extend({
//    copyText2: function (ele) {
//        if (typeof ele !== "string") return false;
//        var input = document.createElement('input');
//        input.setAttribute('type', 'text');
//        input.setAttribute('value', ele);
//        document.body.appendChild(input);
//        input.select();
//        var ret = document.execCommand('copy');
//        document.body.removeChild(input);
//        return ret;
//    },
//})